package com.jrtc.backend.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.base.Strings;
import com.jrtc.base.config.dto.ResultDTO;
import com.jrtc.base.config.dto.ResultDTOBuilder;
import com.jrtc.base.entity.bo.PrescriptionLabelThree;
import com.jrtc.service.PrescriptionLabelThreeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 运动处方三级分类(PrescriptionLabelThree)表控制层
 *
 * @author makejava
 * @since 2022-09-08 13:37:16
 */
@RestController
@RequestMapping("prescriptionLabelThree")
public class PrescriptionLabelThreeController {
    /**
     * 服务对象
     */
    @Resource
    private PrescriptionLabelThreeService prescriptionLabelThreeService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public PrescriptionLabelThree selectOne(Integer id) {
        return this.prescriptionLabelThreeService.queryById(id);
    }
    
    @RequestMapping("getPrescriptionLabelThreeList")
    public ResultDTO getPrescriptionLabelThreeList(@RequestBody PrescriptionLabelThree prescriptionLabelThree)
    {
        IPage<PrescriptionLabelThree> ipage = prescriptionLabelThreeService.queryPrescriptionLabelThreeList(prescriptionLabelThree);
        return ResultDTOBuilder.success(ipage);
    }

    @RequestMapping("insertPrescriptionLabelThree")
    public ResultDTO insertPrescriptionLabelThree(@RequestBody PrescriptionLabelThree prescriptionLabelThree)
    {
        PrescriptionLabelThree tmpPrescriptionLabelThree = prescriptionLabelThreeService.insert(prescriptionLabelThree);
        if (tmpPrescriptionLabelThree != null)
        {
           return ResultDTOBuilder.success("添加成功！");
        }
        return ResultDTOBuilder.failureMsg("添加失败！");
    }

    @RequestMapping("getPrescriptionLabelThreeById")
    public ResultDTO getPrescriptionLabelThreeById(@RequestBody Map<String, String> map)
    {
        String prescriptionLabelThreeId = map.get("prescriptionLabelThreeId");
        PrescriptionLabelThree prescriptionLabelThree = prescriptionLabelThreeService.queryById(Integer.valueOf(prescriptionLabelThreeId));
        if (Strings.isNullOrEmpty(prescriptionLabelThreeId) || prescriptionLabelThree==null)
        {
            return ResultDTOBuilder.failureMsg("信息有误！");
        }
        return ResultDTOBuilder.success(prescriptionLabelThree);
    }

    @RequestMapping("updatePrescriptionLabelThree")
    public ResultDTO updatePrescriptionLabelThree(@RequestBody PrescriptionLabelThree prescriptionLabelThree)
    {
        if (prescriptionLabelThree==null)
        {
            return ResultDTOBuilder.failureMsg("信息有误！");
        }
        if (prescriptionLabelThreeService.update(prescriptionLabelThree)!=null)
        {
            return ResultDTOBuilder.success("修改信息成功！");
        }
        return ResultDTOBuilder.failureMsg("修改信息失败！");
    }
    
    @RequestMapping("deletePrescriptionLabelThree")
    public ResultDTO deletePrescriptionLabelThree(@RequestBody Map<String,String> map)
    {
        String prescriptionLabelThreeId = map.get("prescriptionLabelThreeId");
        if (!Strings.isNullOrEmpty(prescriptionLabelThreeId))
        {
            if (prescriptionLabelThreeService.deleteById(Integer.valueOf(prescriptionLabelThreeId)))
            {
                return ResultDTOBuilder.success("删除成功！");
            }
            return ResultDTOBuilder.failureMsg("删除失败！");
        }
        return ResultDTOBuilder.failureMsg("编号不正确！");
    }
}